package com.sunny.design.proxy.dynamicproxy.customproxy;

import java.lang.reflect.Method;

/**
 * @author Sunny
 * @date 2020/1/1 20:49
 */
public class CustomMeiPo implements CustomInvocationHandler {

    private Object target;

    public Object getInstance(Object target) {
        this.target = target;
        Class<?> clazz = target.getClass();
        return CustomProxy.newProxyInstance(new CustomClassLoader(), clazz.getInterfaces(), this);
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        method.invoke(this.target,args);
        after();
        return null;
    }

    private void before(){
        System.out.println("我是媒婆：我要给你找对象，现在已经拿到你的需求");
        System.out.println("开始物色");
    }

    private void after(){
        System.out.println("如果合适的话，就牵手成功!");
    }
}
